package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.IncomeManage;
import cn.wolfcode.crm.query.IncomeManageQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IIncomeManageService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("incomeManage")
public class IncomeManageController {
    @Autowired
    private IIncomeManageService incomeManageService;

    @RequiresPermissions(value={"incomeManage:view","收款视图"},logical = Logical.OR)
    @RequestMapping("view")
    public String view() {
        return "incomeManage/incomeManage";
    }

    @RequiresPermissions(value={"incomeManage:query","收款列表"},logical = Logical.OR)
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(IncomeManageQueryObject qo) {
        return incomeManageService.query4List(qo);
    }

    @RequiresPermissions(value={"incomeManage:selectAll","收款全选"},logical = Logical.OR)
    @RequestMapping("selectAll")
    @ResponseBody
    public List<IncomeManage> selectAll() {
        return incomeManageService.selectAll();
    }

    @RequiresPermissions(value={"incomeManage:saveOrUpdate","收款编辑/新增"},logical = Logical.OR)
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(IncomeManage entity) {
        try {
            if (entity.getId() == null) {
                incomeManageService.insert(entity);
            } else {
                incomeManageService.updateByPrimaryKey(entity);
            }
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }
    @RequiresPermissions(value={"incomeManage:changState","审核状态"},logical = Logical.OR)
    @RequestMapping("changState")
    @ResponseBody
    public JsonResult changState(Long id) {
        try {
            incomeManageService.changState(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }

    @RequiresPermissions(value={"incomeManage:delete","收款删除"},logical = Logical.OR)
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        try {
            incomeManageService.deleteByPrimaryKey(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }


}
